import requests

from Chaojiying_Python.chaojiying import Chaojiying_Client


class spider(object):
    def __init__(self):
        self.index_url="http://xinanzhijia22.xyz/index.php"
        self.data={
            'username': 'E42214084',
            'password': 'zfKOe7ni',
            'captcha': '',
        }
        self.headers={'user-agent': 'Mozilla/5.0 (X11) AppleWebKit/62.41 (KHTML, like Gecko) Edge/17.10859 Safari/452.6'}

        #开启session会话
        self.s=requests.session()
    def get_index(self):
        #获取验证码图片
        url="http://xinanzhijia22.xyz/toolawd/code.php"
        code_data=self.s.get(url,headers=self.headers).content
        with open("code1.png", "wb") as f:
            f.write(code_data)
        # 识别验证码
        # 超级鹰登录的 账户 密码 软件ID
        chaojiying = Chaojiying_Client('lslols', '12345678asd', '951971')  # 用户中心>>软件ID 生成一个替换 96001
        im = open('./code1.png', 'rb').read()  # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
        code=chaojiying.PostPic(im, 1004)['pic_str']
        print(code)
        self.data['captcha']=str(code)
        response=self.s.post(self.index_url,headers=self.headers,data=self.data)
        print(response.text)
if __name__=='__main__':
    s=spider()
    s.get_index()
